R/Function 2.R

#' oldestplayer.by.year
#'
#' This function allows you to view oldest player in Seasons_Stats_NBA dataset
#' for the year you enter as an argument
#' @param year a numerical value ranging from 1950-2017
#' @return players
#' @examples
#' oldestplayer.by.year()
#' @export
oldestplayer.by.year <- function(dt, year) {
    age <- dplyr::filter(dt, Year == year)
    dplyr::dt[select(Player,Age)]
    with(age, Player[which.max(Age)]) #use which.max instead of max to return the first max value
}
HelloZitong/Package documentation built on May 8, 2019, 8:06 a.m.